<template>
  <div>
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="80px"
      style="width: 500px; margin: 2px"
    >
      <el-form-item label="姓名" prop="userId">
        <el-select
          v-model="form.userId"
          placeholder="请选择巡更人姓名"
          style="width: 419px"
        >
          <el-option label="张三" value="1"></el-option>
          <el-option label="李四" value="2"></el-option>
          <el-option label="王五" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input type="textarea" v-model="form.remark"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="add">保存</el-button>
        <el-button @click="list">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { addPatrolPerson } from "@/api/SafeManage/PatrolPerson";
export default {
  data() {
    return {
      form: {
        userId: "",
        phone: "",
        remark: "",
      },
      rules: {
        userId: [
          { required: true, message: "请选择巡更人姓名", trigger: "change" },
        ],
        phone: [{ required: true, message: "请输入手机号码", trigger: "blur" }],
        remark: [{ required: true, message: "请输入备注", trigger: "blur" }],
      },
    };
  },
  methods: {
    //添加
    add() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          addPatrolPerson(this.form).then((res) => {
            if (res.data) {
              this.$message({
                message: "添加成功",
                type: "success",
              });
              this.$router.push("/SafeManage/PatrolPerson");
            } else {
              this.$message.error("添加失败");
              return;
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //跳转
    list() {
      this.$router.push("/SafeManage/PatrolPerson");
    },
  },
  created() {},
};
</script>
<style>
</style>